import 'dart:ui';

import 'eq_util.dart';

///通道频率信号
class CHSign {
  final double Q;
  final double gain;
  final int freq;
  CHSign({required this.Q, required this.gain, required this.freq});
}

///通道高低通过滤
class CHPass {
  final int freq;
  final int oct_type;
  final bool isHigh;
  final bool isByPass;
  CHPass({required this.freq, required this.oct_type, required this.isHigh, required this.isByPass});
}

class EqTool {
  ///叠加eq,高通，低通，返回的值，直接显示到波形上面
  /// - Parameters:
  ///   - sign_list: 通道有多少个频点信号
  ///   - high_pass: 高通
  ///   - low_pass: 低通
  ///   - size: 通道的频点组成的波形，显示的宽度
  ///   - sign_by: 根据波形显示的高度，自定义调整的eq的系数，20
  ///   - pass_by: 根据波形显示的高度，自定义调整的高低通叠加的系数，0.5555556 * 25
  /// - Returns: 映射后的整数
  static List<double> eqTotal(
      List<CHSign> sign_list, CHPass high_pass, CHPass low_pass, Size size, double sign_by, double pass_by) {
    List<double> result = List<double>.filled(size.width.toInt(), 0.0);

    ///1,计算通道信号的增益
    for (var sign in sign_list) {
      List<double> list = List<double>.filled(size.width.toInt(), 0.0);
      EQUtil.eq(sign.Q, sign.gain, sign.freq.toDouble(), list);
      result = List<double>.generate(size.width.toInt(), (i) => result[i] + list[i] * sign_by);
    }

    ///2,计算通道的高通
    List<double> temp1 = List<double>.filled(size.width.toInt(), 0.0);
    temp1 = EQUtil.filter(high_pass.freq.toDouble(), high_pass.oct_type, high_pass.isHigh, high_pass.isByPass, temp1);
    result = List<double>.generate(size.width.toInt(), (i) => result[i] + temp1[i] * pass_by);

    ///3,计算通道的低通
    List<double> temp2 = List<double>.filled(size.width.toInt(), 0.0);
    temp2 = EQUtil.filter(low_pass.freq.toDouble(), low_pass.oct_type, low_pass.isHigh, low_pass.isByPass, temp1);
    result = List<double>.generate(size.width.toInt(), (i) => result[i] + temp2[i] * pass_by);

    ///4,按比例，计算高度
    // result = List<double>.generate(width.toInt(), (i) => result[i] * 13);
    return result;
  }
}
